<template>
  <div class="gateway-container">
    <div class="app-container home bg-white">
    <div class="banner"></div>
      <div class="container">
        <el-breadcrumb separator="/" class="ml20">
          <el-breadcrumb-item :to="{ path: '/gateway' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{path: prevPath}">文章列表</el-breadcrumb-item>
          <el-breadcrumb-item>文章详情</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="details-content ql-editor ">
          <h1 class="text-center">{{ noticeData.noticeTitle }}</h1>
          <hr class="mt20 mb20">
          <div v-html="noticeData.noticeContent"></div>
        </div>
        <hr class="mt20 mb20" v-if="showAttach">
        <div class="details-attach" v-if="showAttach">
          <div class="details-attach-title">附件下载：</div>
          <ul>
            <li v-for="row in attachList" :key="row.attachmentId">
              <el-link type="primary" @click="handleDownload(row)">{{row.fileName}}</el-link>
            </li>
          </ul>
        </div>
      </div>
      <div class="footer">
      </div>
    </div>
  </div>
</template>


<script>
  import { getNotice } from '@/api/system/notice'
  import {listNoticeAttachById} from '@/api/system/noticeAttach'

  export default {
    name: 'GatewayDetails',
    data() {
      return {
        noticeData: {},
        attachList: [],
        noticeId: null
      }
    },
    computed: {
      prevPath() {
        return `/gateway-list?noticeType=${this.noticeData.noticeType}`
      },
      showAttach() {
        return this.attachList.length > 0
      }
    },
    async created() {
      const noticeId = this.$route.query && this.$route.query.noticeId;
      this.noticeId = noticeId
      const noticeData = await getNotice(noticeId)
      this.$set(this, 'noticeData', noticeData.data)
      const attach = await listNoticeAttachById(noticeId)
      this.$set(this, 'attachList', attach.data)
    },
    methods: {
      backPrev() {
        this.$router.back()
      },
      // 文件下载处理
      handleDownload(row) {
        const name = row.fileName;
        const url = row.filePath;
        // const suffix = url.substring(url.lastIndexOf("."), url.length);
        const a = document.createElement('a')
        a.setAttribute('download', name)
        a.setAttribute('target', '_blank')
        a.setAttribute('href', url)
        a.click()
      },
    }
  }
</script>

<style lang="scss">
.details-content {
  padding: 15px;
  margin-bottom: 20px;
  min-height: 960px;
  img {
    max-width: 55%;
  }
  p {
    margin: 0;
  }
}

</style>

<style scoped lang="scss">
.footer {
  border-top: 1px solid #1e1e1e;
}

.details-attach {
  > ul {
    list-style: none;
    margin-top: 5px;
  }

  &-title {
    margin-left: 40px;
    font-size: 14px;
  }
}

.list-content {
  min-height: 900px;
}
</style>
